import { getAvatar, getMine } from "@/api/user";
import { defineStore } from "pinia";
import { reactive } from "vue";

export const useAccountSettings = defineStore("account-settings", () => {
  const userInfos = reactive({
    id: "",
    avatar: "",
    nickname: "",
    email: "",
    phone: "",
    description: "",
    username: ""
  });
  const getUserInfo = async () => {
    const res = await getMine();
    if (!res.data.avatar) {
      return; // 没有头像，不进行处理
    }
    const avatar = await getAvatar(res.data.avatar);
    res.data.avatar = URL.createObjectURL(avatar);
    Object.assign(userInfos, res.data);
  };
  // onMounted(() => {
  //   getUserInfo();
  // });
  return { userInfos, getUserInfo };
});
